function generateMfuncMkernel(nameSteadyState,strucOfArrays,position,nameOfFunction)
% This function generates an M function which evaluates all second order 
% derivatives to a DSGE model at the steady state.  


% We start deleting the old version of the file - if it exists
saveFile = [position,'\',nameOfFunction];
if exist(saveFile,'file') > 0
    delete(saveFile)
end

% Clears the command windue
clc;
    
% The results are saved
diary(saveFile);

disp(['function [M,Mxp,Myp,Mxpx,Mxpxp,Mxpy,Mxpyp,Mypx,Mypxp,Mypy,Mypyp] = ',nameOfFunction(1:end-2),'(params)'])
disp(' ')
disp('%The steady state of the model')
disp([nameSteadyState,';']);
disp(' ');

disp('%Setting dimension for the matrices');
disp('ny  = auxOut.ny;');
disp('nx  = auxOut.nx;');
disp('Mxp   = zeros(1,nx);')
disp('Myp   = zeros(1,ny);')
disp('Mxpx  = zeros(nx,nx);')
disp('Mxpxp = zeros(nx,nx);')
disp('Mxpy  = zeros(nx,ny);')
disp('Mxpyp = zeros(nx,ny);')
disp('Mypx  = zeros(ny,nx);')
disp('Mypxp = zeros(ny,nx);')
disp('Mypy  = zeros(ny,ny);')
disp('Mypyp = zeros(ny,ny);')
disp(' ');


names = fieldnames(strucOfArrays);
nn = size(names,1);
for i=1:nn
    DispSymMatrixMatlab(strucOfArrays.(names{i}),names{i})
    disp(' ');
end

disp('end')
diary off;
end





